<template>
  <div id=''>
    <van-button
            class="follow-btn"
            type="info"
            color="#3296fa"
            round
            size="small"
            icon="plus"
            v-if="!is_followed"
            @click="onFollowed"
            >关注</van-button
          >
          <van-button
            class="follow-btn"
            round
            size="small"
            v-else
            @click="onFollowed"
            >已关注</van-button
          >
  </div>
</template>

<script>
import { addUserFollow, deleteUserFollow } from '@/api/user.js'
import { Toast } from 'vant'

export default {
  props: {
    is_followed: {
      type: Boolean,
      required: true
    },
    aut_id: {
      type: [Number, Object],
      required: true
    }
  },
  model: {
    prop: 'is_followed',
    event: 'updataFollowed'
  },
  data () {
    return {

    }
  },

  // 定义方法
  methods: {
    onFollowed () {
      try {
        if (this.is_followed) {
          deleteUserFollow(this.aut_id)
        } else {
          addUserFollow(this.aut_id)
        }
        this.$emit('updataFollowed', !this.is_followed)
      } catch (err) {
        Toast('失败！')
      }
    }
  }
}

</script>

<style scoped lang='less'>

</style>
